import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: zhongyisheng
 * Date: 2024-05-15
 * Time: 16:22
 */
public class Test {
    public static void sort (int[] array) {
        for (int i = 0; i < array.length-1; i++) {
            for (int j = 0; j < array.length-1-i; j++) {
                if(array[j]>array[j+1]){
                    int tmp=array[j];
                    array[j]=array[j+1];
                    array[j+1]=tmp;
                }
            }
        }
    }

    public static void main(String[] args) {
        int[] array = {2,3,1,9,6,8,5,7,4};
        System.out.println(Arrays.toString(array));
        sort(array);
        System.out.println(Arrays.toString(array));
    }




    public static int binarySearch(int[] array,int k) {
        int left=0;
        int right=array.length-1;
        while(left<=right) {
            int mid=(left>>>1)+(right>>>1);
            if (array[mid] > k) {
                right = mid-1;
            } else if (array[mid] < k) {
                left = mid+1;
            } else {
                return mid;
            }
        }
        return -1;
    }


    public static void main3(String[] args) {
        int[] array={1,2,3,4,5,6,7,8,9};
        int ret=binarySearch(array,7);
        System.out.println(ret);
    }

    public static String myToString(int[] array) {
        String ret="[";
        for (int i = 0; i < array.length; i++) {
            ret+=array[i];
            if (i!=array.length-1)
                ret+=",";
        }
        ret+="]";
        return ret;

    }
    public static void main2(String[] args) {
        int[] arrar={1,2,3,4,5};
        System.out.println(myToString(arrar));
        int[] arrar2={1,2,3,4,5,6,45,3,2345,23,5,};
        System.out.println(myToString(arrar2));

    }

    public static int[] func(int[] array) {
        int[] ret=new int[array.length];
        for (int i = 0; i < array.length; i++) {
            ret[i]=array[i]*2;
        }
        return ret;
    }
    public static void main1(String[] args) {
        int[] array = {1,2,3,4,5,6};
        array = func(array);
        System.out.println(Arrays.toString(array));

    }
}
